/**
 * 基于ZC项目的网络请求工具类
 */
const Tool = {waitForResponse,};

/**
 * 等待网络响应
 * @param page Puppeteer的页面
 * @param url 请求路径
 */
async function waitForResponse(page, url) {
  let responseText;
  await page.waitForResponse(response => {
    responseText = response.text();
    return response.url().indexOf(url) > 1 && response.status() === 200;
  });
  return responseText.then((result) => JSON.parse(result));;
}

module.exports = Tool;
